package db.daos;

import Conexao.Conexao;
import db.beans.TipoUsuario;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Denis
 */
public class TipoUsuarioDao {
    public static TipoUsuario BuscaTipo(String descricao){    
		
                Conexao con = Conexao.getInstancia();
		String query = "SELECT idTipo,descricao FROM tipousuario WHERE descricao=?";
                    
                    TipoUsuario aux = null;
                con.preparar(query);
		try {
                    
                    con.getPs().setString(1,descricao);
                    ResultSet rs = con.executeQuery();
			if(rs.next()){
                            aux = new TipoUsuario();
			    aux.setTipo(rs.getInt("idTipo"));
			    aux.setDescricao(rs.getString("descricao"));
                        }
		} catch (SQLException e) {
			
			e.printStackTrace();
		} finally {
			return(aux);
		}
    }
    public static TipoUsuario BuscaId(int id){    
		
                Conexao con = Conexao.getInstancia();
		String query = "SELECT idTipo,descricao FROM tipousuario WHERE idTipo=?";
                    
                    TipoUsuario aux = null;
                con.preparar(query);
		try {
                    con.getPs().setInt(1,id);
                    ResultSet rs = con.executeQuery();
			if(rs.next()){
                            aux = new TipoUsuario();
			    aux.setTipo(rs.getInt("idTipo"));
			    aux.setDescricao(rs.getString("descricao"));
                        }
		} catch (SQLException e) {
			
			e.printStackTrace();
		} finally {
			return(aux);
		}
    }
}
